//
// Created by francklinson on 2021/11/22 AT 0:41.
// May Saint Diana bless you!
//

#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <functional>
#include <climits>
#include <string>

using namespace std;

class Solution {
public:
    string sortSentence(string s) {
        //  1.切分句子
        vector<string> v(10);
        int start = 0;
        for (int i = 0; i < s.size(); ++i) {
            if (isdigit(s[i])) {
                v[s[i] - '0'] = s.substr(start, i - start);
                start = i + 2;
            }
        }
        //  2.重构句子
        string ans;
        for (int i = 1; i <= 9; ++i) {
            if (v[i].empty())
                break;
            ans += v[i];
            ans += ' ';
        }
        ans.pop_back();// 去掉句尾多余的空格
        return ans;
    }
};

int main() {
    Solution solution;
    cout << solution.sortSentence("is2 sentence4 This1 a3") << endl;
    cout << solution.sortSentence("Myself2 Me1 I4 and3") << endl;
    return 0;
}

